import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBApplication.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBImageStyle/YBImageStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBWorkTaiBaseYiJiModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBWorkTaiModule/YBZhuanShuYingYongPage/YBMiShuProvider/YBMiShuTimeEventBus.dart';

import 'YBMiShuProvider/YBMiShuProvider.dart';
import 'YBMiShuSubPage/YBMiShuTongListYiHuoFeedStatusPage.dart';

class YBMiShuYiJiHeLvSiMainPage extends StatefulWidget {

  final String miType;

  const YBMiShuYiJiHeLvSiMainPage({Key key, this.miType}) : super(key: key);

  @override
  _YBMiShuYiJiHeLvSiMainPageState createState() => _YBMiShuYiJiHeLvSiMainPageState(miType: miType);
}

class _YBMiShuYiJiHeLvSiMainPageState extends State<YBMiShuYiJiHeLvSiMainPage> {

  final String miType;

  _YBMiShuYiJiHeLvSiMainPageState({this.miType});

  bool _selectTime = false;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();


  }


  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Container(
            alignment: Alignment.centerLeft,
            height: YBTextStyle.adapterSize28,
            color: YBColor.common2D69E0,
            child: Padding(
              padding: EdgeInsets.only(left: YBTextStyle.adapterSize20),
              child: Text(YBChineseText.workTaiYouXiaoToastInfo,
                maxLines: 1,
                style:YBTextStyle.TextStyleA9AEB813,
              ),
            ),
          ),
          Container(
            height: YBTextStyle.adapterSize44,
            color: YBColor.white,
            child: Padding(
              padding:EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
              child: Row(
                children: [
                  Container(
                    child: InkWell(
                      child: Text(
                        YBChineseText.workTaiTimeDaoXuTitle,
                        style: _selectTime == false?YBTextStyle.TextStyle2D69E013Medium:YBTextStyle.TextStyle7A7A7A013Medium,
                      ),
                      onTap: () async {
                        setState(() {
                          _selectTime = !_selectTime;
                          timeEventBus.fire(YBMiShuTimeEventBus(selectTimeDian: _selectTime));
                        });
                      },
                    ),
                  ),
                  Container(
                    width: YBTextStyle.adapterSize15,
                  ),
                  Container(
                    child: InkWell(
                      child: Text(
                        YBChineseText.workTaiTimeZhengXuTitle,
                        style: _selectTime ==true?YBTextStyle.TextStyle2D69E013Medium:YBTextStyle.TextStyle7A7A7A013Medium,
                      ),
                      onTap: () async {
                          setState(() {
                            _selectTime = !_selectTime;
                            timeEventBus.fire(YBMiShuTimeEventBus(selectTimeDian: _selectTime));
                          });
                      },
                    )
                  ),
                  Expanded(
                    child:Container(
                      alignment: Alignment.centerRight,
                      child: Row(
                        mainAxisAlignment:MainAxisAlignment.end,
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                            child: Image.asset(YBImageStyle.getImagePath('')),
                          ),
                          Container(
                            width: YBTextStyle.adapterSize5,
                          ),
                          Container(
                            child: Text(
                              YBChineseText.workTaiShaiXuanTitle,
                              style:YBTextStyle.TextStyle7A7A7A011,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
          Expanded(
            child: ChangeNotifierProvider(
              create: (context) => YBYiJiLvSiBaseYiHuoProvider()..getYiHuoDataList(1, miType, "1", "", "get_time", "desc"),
              child: Consumer<YBYiJiLvSiBaseYiHuoProvider>(
                builder: (context,yijiLvSiBaseList,child){

                  timeEventBus.on<YBMiShuTimeEventBus>().listen((event) {
                     yijiLvSiBaseList.getYiHuoDataList(1, miType, "1", "", "get_time", event.selectTimeDian?"asc":"desc");
                  });

                  return SmartRefresher(
                    controller:yijiLvSiBaseList.easyRefreshController,
                    onRefresh: () async {
                      yijiLvSiBaseList.refreshData(miType, "1", "", "get_time", _selectTime?"asc":"desc");
                    },
                    onLoading: () async {
                      yijiLvSiBaseList.loadData(miType, "1", "", "get_time", _selectTime?"asc":"desc");
                    },
                    enablePullUp: true,
                    enablePullDown: true,
                    child: CustomScrollView(
                      slivers: [
                        SliverList(
                          delegate: SliverChildBuilderDelegate((_,int index){
                            YBWorkTaiBaseYiJiModel yijiModel = yijiLvSiBaseList.yiHuoModelList[index];
                            // print('--status-${yijiModel.request.requestServiceDesc}-');
                            //
                            return Container(
                              child: InkWell(
                                child: YBMiShuTongYiHuoFeedStausPage(timeStr: yijiModel.getTime,statusStr: yijiModel.feedbackStatus.toString(),contentStr: yijiModel.request.requestServiceDesc,statusPageType: YBMiShuYiHuoFeedStatusPageType.YBMiShuYiHuoFeedStatusPageType_YiHuoShangJi,),
                                onTap: () async {
                                  YBApplication.router.navigateTo(context, '/workTaiPage/workTaiMiShuTongPage/workTaiMiShuShangJikuPage/workTaiMiShuYouXuanShangJiDetailPage?syscode=$miType&requestcode=${yijiModel.requestCode}&&feedStatus=${yijiModel.feedbackStatus.toString()}');
                                },
                              ),
                            );
                          },
                            childCount: yijiLvSiBaseList.yiHuoModelList.length,
                          ),
                        ),
                      ],
                    ),
                  );
                },
              ),
            ),
          ),
        ],
      ),
    );
  }
}

